#include "GY_PropertyInfo.h"
#include "../GY_Object.h"

GY_PropertyInfo::GY_PropertyInfo(QObject *parent) : QObject(parent)
{
    propertyType=PropertyType::IntPropertyType;
    updateType=PropertyUpdateType::NotUpdate;
}

GY_PropertyInfo::GY_PropertyInfo(const GY_PropertyInfo &other) : QObject(other.parent())
{
    this->propertyName = other.propertyName;
    this->propertyType = other.propertyType;
    this->propertyValue = other.propertyValue;
    this->updatePropertyFun = other.updatePropertyFun;
    this->updateType = other.updateType;
}

GY_PropertyInfo::~GY_PropertyInfo()
{

}

GY_PropertyInfo &GY_PropertyInfo::operator=(const GY_PropertyInfo &value)
{
    if(this != &value) {
        this->propertyName = value.propertyName;
        this->propertyType = value.propertyType;
        this->propertyValue = value.propertyValue;
        this->updatePropertyFun = value.updatePropertyFun;
        this->updateType = value.updateType;
    }
    return *this;
}

void GY_PropertyInfo::setConnect()
{
    if(this->parent())
    {
        connect(&propertyValue,&GY_Variant::sendValueSig,this,[=](const QVariant &value) {
            if((updateType&Update) == Update) {
                emit ((GY_Object*)(this->parent()))->updatePropertyEvent(((GY_Object const*)(this->parent())),
                        propertyName,((GY_Object*)(this->parent()))->submittingPropertyValues(updateType,value,((GY_Object *)this->parent())->getGraphicsItem()),propertyType);
            }
        },Qt::UniqueConnection);
    }

}


